package com.junzhiit.nengji.cms.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.PostageTemplateService;
import com.junzhiit.nengji.cms.web.vo.PostageTemplateAddVO;
import com.junzhiit.nengji.cms.web.vo.PostageTemplateEditVO;
import com.junzhiit.nengji.cms.web.vo.PostageTemplateVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

@RestController
@RequestMapping("/postage/template")
public class PostageTemplateController extends BaseController {

	@Autowired
	private PostageTemplateService postageTemplateService;
	
	@RequestMapping(method=RequestMethod.POST)
	public ResultVO add(PostageTemplateAddVO postageTemplateAddVO){
		AssertUtil.notBlank(postageTemplateAddVO.getName(), "name is required");
		AssertUtil.notNull(postageTemplateAddVO.getValuateType(), "valuateType is required");
		return postageTemplateService.add(postageTemplateAddVO);
	}
	
	@RequestMapping(method=RequestMethod.PUT)
	public ResultVO edit(PostageTemplateEditVO postageTemplateEditVO){
		AssertUtil.notBlank(postageTemplateEditVO.getName(), "name is required");
		AssertUtil.notNull(postageTemplateEditVO.getValuateType(), "valuateType is required");
		return postageTemplateService.edit(postageTemplateEditVO);
	}
	
	@RequestMapping(method=RequestMethod.GET)
	public ResultVO getAllBO(PostageTemplateVO postageTemplateVO){
		AssertUtil.notBlank(postageTemplateVO.getSessionId(), "sessionId is required");
		return postageTemplateService.getAllBO(postageTemplateVO);
		
	}
	
	@RequestMapping(value="bo",method=RequestMethod.GET)
	public ResultVO getBO(PostageTemplateVO postageTemplateVO){
		AssertUtil.notBlank(postageTemplateVO.getSessionId(), "sessionId is required");
		AssertUtil.notBlank(postageTemplateVO.getId(), "id is required");
		return postageTemplateService.getBO(postageTemplateVO);
	}
	
	@RequestMapping(value="del",method=RequestMethod.PUT)
	public ResultVO delete(String id){
		AssertUtil.notBlank(id, "id is required");
		return postageTemplateService.delete(id);
	}
	
	@RequestMapping(value="all",method=RequestMethod.GET)
	public ResultVO getAll(String sessionId){
		AssertUtil.notBlank(sessionId, "sessionId is required");
		return postageTemplateService.getAll(sessionId);
	}
	
}
